package com.sbj.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.CouponsReq;
import com.sbj.dto.res.CouponsRes;
import com.sbj.entity.Coupons;
import com.sbj.mapper.CouponsMapper;
import com.sbj.service.ICouponsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author summer
 * @since 2024/08/10 10:02:40
 */
@Service
public class CouponsServiceImpl extends ServiceImpl<CouponsMapper, Coupons> implements ICouponsService {

    @Override
    public Page<CouponsRes> lists(CouponsReq couponsReq) {
         Page<Coupons> page=new Page<>(couponsReq.getPageNum(),couponsReq.getPageSize());
         LambdaQueryWrapper<Coupons> like = Wrappers.lambdaQuery(Coupons.class).like(StrUtil.isNotEmpty(couponsReq.getName()), Coupons::getName, couponsReq.getName());
        return Convert.convert(new TypeReference<Page<CouponsRes>>() {},this.page(page,like));
    }
}
